package com.aos.eap.activity;

import android.content.res.Resources;
import android.view.KeyEvent;
import android.widget.Toast;

import com.aos.eap.R;
import com.aos.eap.fragment.IndexFragment;
import com.aos.eap.fragment.SearchFragment;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabEntity;
import com.pda.platform.ui.ui_pdaplatform.tablayout.CommonTabLayout;
import com.pda.platform.ui.ui_pdaplatform.tablayout.listener.CustomTabEntity;

import java.util.ArrayList;

import androidx.fragment.app.Fragment;
import butterknife.BindView;

public class HomeActivity extends FreeUI_BaseActivity {
    @BindView(R.id.tabLayout)
    CommonTabLayout tabLayout;

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private long exitTime = 0;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_home;
    }

    @Override
    protected void initView() {

    }


    @Override
    protected void initData() {
        mFragments.add(new IndexFragment());
        mFragments.add(new SearchFragment());
//        mFragments.add(new MineFragment());

        Resources resources = getResources();
        mTabEntities.add(new FreeUI_TabEntity("首页",
                resources.getDrawable(R.drawable.aos_home_select), resources.getDrawable(R.drawable.aos_home_no_select)));
        mTabEntities.add(new FreeUI_TabEntity("查询",
                resources.getDrawable(R.drawable.aos_search_select), resources.getDrawable(R.drawable.aos_search_unselect)));
//        mTabEntities.add(new FreeUI_TabEntity("我的",
//                resources.getDrawable(R.drawable.aos_mine_select), resources.getDrawable(R.drawable.aos_mine_no_select)));

        tabLayout.setTabData(mTabEntities, this, R.id.content, mFragments);
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
